
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>8. Data Types &#8212; Python 3.6.3 documentation</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.6.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.6.3 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="8.1. datetime — Basic date and time types" href="datetime.html" />
    <link rel="prev" title="7.2. codecs — Codec registry and base classes" href="codecs.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/datatypes.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    <script type="text/javascript" src="../_static/switchers.js"></script>
    
    
 

  </head>
  <body>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="datetime.html" title="8.1. datetime — Basic date and time types"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="codecs.html" title="7.2. codecs — Codec registry and base classes"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <span class="language_switcher_placeholder">en</span>
          <span class="version_switcher_placeholder">3.6.3</span>
          <a href="../index.html">Documentation </a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">The Python Standard Library</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="data-types">
<span id="datatypes"></span><h1>8. Data Types<a class="headerlink" href="#data-types" title="Permalink to this headline">¶</a></h1>
<p>The modules described in this chapter provide a variety of specialized data
types such as dates and times, fixed-type arrays, heap queues, synchronized
queues, and sets.</p>
<p>Python also provides some built-in data types, in particular,
<a class="reference internal" href="stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal"><span class="pre">dict</span></code></a>, <a class="reference internal" href="stdtypes.html#list" title="list"><code class="xref py py-class docutils literal"><span class="pre">list</span></code></a>, <a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal"><span class="pre">set</span></code></a> and <a class="reference internal" href="stdtypes.html#frozenset" title="frozenset"><code class="xref py py-class docutils literal"><span class="pre">frozenset</span></code></a>, and
<a class="reference internal" href="stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal"><span class="pre">tuple</span></code></a>.  The <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal"><span class="pre">str</span></code></a> class is used to hold
Unicode strings, and the <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a> class is used to hold binary data.</p>
<p>The following modules are documented in this chapter:</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="datetime.html">8.1. <code class="docutils literal"><span class="pre">datetime</span></code> — Basic date and time types</a><ul>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#available-types">8.1.1. Available Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#timedelta-objects">8.1.2. <code class="docutils literal"><span class="pre">timedelta</span></code> Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#date-objects">8.1.3. <code class="docutils literal"><span class="pre">date</span></code> Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#datetime-objects">8.1.4. <code class="docutils literal"><span class="pre">datetime</span></code> Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#time-objects">8.1.5. <code class="docutils literal"><span class="pre">time</span></code> Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#tzinfo-objects">8.1.6. <code class="docutils literal"><span class="pre">tzinfo</span></code> Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#timezone-objects">8.1.7. <code class="docutils literal"><span class="pre">timezone</span></code> Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetime.html#strftime-and-strptime-behavior">8.1.8. <code class="docutils literal"><span class="pre">strftime()</span></code> and <code class="docutils literal"><span class="pre">strptime()</span></code> Behavior</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="calendar.html">8.2. <code class="docutils literal"><span class="pre">calendar</span></code> — General calendar-related functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="collections.html">8.3. <code class="docutils literal"><span class="pre">collections</span></code> — Container datatypes</a><ul>
<li class="toctree-l2"><a class="reference internal" href="collections.html#chainmap-objects">8.3.1. <code class="docutils literal"><span class="pre">ChainMap</span></code> objects</a><ul>
<li class="toctree-l3"><a class="reference internal" href="collections.html#chainmap-examples-and-recipes">8.3.1.1. <code class="docutils literal"><span class="pre">ChainMap</span></code> Examples and Recipes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#counter-objects">8.3.2. <code class="docutils literal"><span class="pre">Counter</span></code> objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#deque-objects">8.3.3. <code class="docutils literal"><span class="pre">deque</span></code> objects</a><ul>
<li class="toctree-l3"><a class="reference internal" href="collections.html#deque-recipes">8.3.3.1. <code class="docutils literal"><span class="pre">deque</span></code> Recipes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#defaultdict-objects">8.3.4. <code class="docutils literal"><span class="pre">defaultdict</span></code> objects</a><ul>
<li class="toctree-l3"><a class="reference internal" href="collections.html#defaultdict-examples">8.3.4.1. <code class="docutils literal"><span class="pre">defaultdict</span></code> Examples</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#namedtuple-factory-function-for-tuples-with-named-fields">8.3.5. <code class="docutils literal"><span class="pre">namedtuple()</span></code> Factory Function for Tuples with Named Fields</a></li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#ordereddict-objects">8.3.6. <code class="docutils literal"><span class="pre">OrderedDict</span></code> objects</a><ul>
<li class="toctree-l3"><a class="reference internal" href="collections.html#ordereddict-examples-and-recipes">8.3.6.1. <code class="docutils literal"><span class="pre">OrderedDict</span></code> Examples and Recipes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#userdict-objects">8.3.7. <code class="docutils literal"><span class="pre">UserDict</span></code> objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#userlist-objects">8.3.8. <code class="docutils literal"><span class="pre">UserList</span></code> objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="collections.html#userstring-objects">8.3.9. <code class="docutils literal"><span class="pre">UserString</span></code> objects</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="collections.abc.html">8.4. <code class="docutils literal"><span class="pre">collections.abc</span></code> — Abstract Base Classes for Containers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="collections.abc.html#collections-abstract-base-classes">8.4.1. Collections Abstract Base Classes</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="heapq.html">8.5. <code class="docutils literal"><span class="pre">heapq</span></code> — Heap queue algorithm</a><ul>
<li class="toctree-l2"><a class="reference internal" href="heapq.html#basic-examples">8.5.1. Basic Examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="heapq.html#priority-queue-implementation-notes">8.5.2. Priority Queue Implementation Notes</a></li>
<li class="toctree-l2"><a class="reference internal" href="heapq.html#theory">8.5.3. Theory</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="bisect.html">8.6. <code class="docutils literal"><span class="pre">bisect</span></code> — Array bisection algorithm</a><ul>
<li class="toctree-l2"><a class="reference internal" href="bisect.html#searching-sorted-lists">8.6.1. Searching Sorted Lists</a></li>
<li class="toctree-l2"><a class="reference internal" href="bisect.html#other-examples">8.6.2. Other Examples</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="array.html">8.7. <code class="docutils literal"><span class="pre">array</span></code> — Efficient arrays of numeric values</a></li>
<li class="toctree-l1"><a class="reference internal" href="weakref.html">8.8. <code class="docutils literal"><span class="pre">weakref</span></code> — Weak references</a><ul>
<li class="toctree-l2"><a class="reference internal" href="weakref.html#weak-reference-objects">8.8.1. Weak Reference Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="weakref.html#example">8.8.2. Example</a></li>
<li class="toctree-l2"><a class="reference internal" href="weakref.html#finalizer-objects">8.8.3. Finalizer Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="weakref.html#comparing-finalizers-with-del-methods">8.8.4. Comparing finalizers with <code class="docutils literal"><span class="pre">__del__()</span></code> methods</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="types.html">8.9. <code class="docutils literal"><span class="pre">types</span></code> — Dynamic type creation and names for built-in types</a><ul>
<li class="toctree-l2"><a class="reference internal" href="types.html#dynamic-type-creation">8.9.1. Dynamic Type Creation</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#standard-interpreter-types">8.9.2. Standard Interpreter Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#additional-utility-classes-and-functions">8.9.3. Additional Utility Classes and Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#coroutine-utility-functions">8.9.4. Coroutine Utility Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="copy.html">8.10. <code class="docutils literal"><span class="pre">copy</span></code> — Shallow and deep copy operations</a></li>
<li class="toctree-l1"><a class="reference internal" href="pprint.html">8.11. <code class="docutils literal"><span class="pre">pprint</span></code> — Data pretty printer</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pprint.html#prettyprinter-objects">8.11.1. PrettyPrinter Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="pprint.html#example">8.11.2. Example</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="reprlib.html">8.12. <code class="docutils literal"><span class="pre">reprlib</span></code> — Alternate <code class="docutils literal"><span class="pre">repr()</span></code> implementation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="reprlib.html#repr-objects">8.12.1. Repr Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="reprlib.html#subclassing-repr-objects">8.12.2. Subclassing Repr Objects</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="enum.html">8.13. <code class="docutils literal"><span class="pre">enum</span></code> — Support for enumerations</a><ul>
<li class="toctree-l2"><a class="reference internal" href="enum.html#module-contents">8.13.1. Module Contents</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#creating-an-enum">8.13.2. Creating an Enum</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#programmatic-access-to-enumeration-members-and-their-attributes">8.13.3. Programmatic access to enumeration members and their attributes</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#duplicating-enum-members-and-values">8.13.4. Duplicating enum members and values</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#ensuring-unique-enumeration-values">8.13.5. Ensuring unique enumeration values</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#using-automatic-values">8.13.6. Using automatic values</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#iteration">8.13.7. Iteration</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#comparisons">8.13.8. Comparisons</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#allowed-members-and-attributes-of-enumerations">8.13.9. Allowed members and attributes of enumerations</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#restricted-subclassing-of-enumerations">8.13.10. Restricted subclassing of enumerations</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#pickling">8.13.11. Pickling</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#functional-api">8.13.12. Functional API</a></li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#derived-enumerations">8.13.13. Derived Enumerations</a><ul>
<li class="toctree-l3"><a class="reference internal" href="enum.html#intenum">8.13.13.1. IntEnum</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#intflag">8.13.13.2. IntFlag</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#flag">8.13.13.3. Flag</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#others">8.13.13.4. Others</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#interesting-examples">8.13.14. Interesting examples</a><ul>
<li class="toctree-l3"><a class="reference internal" href="enum.html#omitting-values">8.13.14.1. Omitting values</a><ul>
<li class="toctree-l4"><a class="reference internal" href="enum.html#using-auto">8.13.14.1.1. Using <code class="docutils literal"><span class="pre">auto</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#using-object">8.13.14.1.2. Using <code class="docutils literal"><span class="pre">object</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#using-a-descriptive-string">8.13.14.1.3. Using a descriptive string</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#using-a-custom-new">8.13.14.1.4. Using a custom <code class="docutils literal"><span class="pre">__new__()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#orderedenum">8.13.14.2. OrderedEnum</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#duplicatefreeenum">8.13.14.3. DuplicateFreeEnum</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#planet">8.13.14.4. Planet</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="enum.html#how-are-enums-different">8.13.15. How are Enums different?</a><ul>
<li class="toctree-l3"><a class="reference internal" href="enum.html#enum-classes">8.13.15.1. Enum Classes</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#enum-members-aka-instances">8.13.15.2. Enum Members (aka instances)</a></li>
<li class="toctree-l3"><a class="reference internal" href="enum.html#finer-points">8.13.15.3. Finer Points</a><ul>
<li class="toctree-l4"><a class="reference internal" href="enum.html#supported-dunder-names">8.13.15.3.1. Supported <code class="docutils literal"><span class="pre">__dunder__</span></code> names</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#supported-sunder-names">8.13.15.3.2. Supported <code class="docutils literal"><span class="pre">_sunder_</span></code> names</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#enum-member-type">8.13.15.3.3. <code class="docutils literal"><span class="pre">Enum</span></code> member type</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#boolean-value-of-enum-classes-and-members">8.13.15.3.4. Boolean value of <code class="docutils literal"><span class="pre">Enum</span></code> classes and members</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#enum-classes-with-methods">8.13.15.3.5. <code class="docutils literal"><span class="pre">Enum</span></code> classes with methods</a></li>
<li class="toctree-l4"><a class="reference internal" href="enum.html#combining-members-of-flag">8.13.15.3.6. Combining members of <code class="docutils literal"><span class="pre">Flag</span></code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="codecs.html"
                        title="previous chapter">7.2. <code class="docutils literal"><span class="pre">codecs</span></code> — Codec registry and base classes</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="datetime.html"
                        title="next chapter">8.1. <code class="docutils literal"><span class="pre">datetime</span></code> — Basic date and time types</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">Report a Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.6/Doc/library/datatypes.rst"
            rel="nofollow">Show Source
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="datetime.html" title="8.1. datetime — Basic date and time types"
             >next</a> |</li>
        <li class="right" >
          <a href="codecs.html" title="7.2. codecs — Codec registry and base classes"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <span class="language_switcher_placeholder">en</span>
          <span class="version_switcher_placeholder">3.6.3</span>
          <a href="../index.html">Documentation </a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 2001-2017, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Oct 14, 2017.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.6.4.
    </div>

  </body>
</html>